package demo.DataStrucAndAlgo.Easy_pritice;

import java.util.Stack;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/9/7-09-07-18:47
 * @Description：demo.DataStrucAndAlgo.Easy_pritice
 */
public class UsingChar {
    public static void main(String[] args) {
        longestValidParentheses("(()");
        System.out.println(Math.floor(-6.7));

    }
    public static int longestValidParentheses(String s) {
        int left = 0, right = 0;
        int max = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(') {
                left++;
            } else {
                right++;
            }
            if (left < right) {
                right = 0;
                left = 0;
            } else if (left == right) {
                if (max < left * 2) {
                    max = left * 2;
                }
            }
        }
        left = right = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) == '(') {
                left++;
            } else {
                right++;
            }
            if (left > right) {
                right = 0;
                left = 0;
            } else if (left == right) {
                if (max < left * 2) {
                    max = left * 2;
                }
            }
        }
        return max;
    }
}
